//Created by  for Jaws.Core.Web
//Original work Copyright(C) 2008.  All Rights Reserved.

using System;

namespace Jaws.Core.Web.Entities.Validation.CustomAttributes
{
    public class IsDateAttribute : ValidationAttribute
    {
        public IsDateAttribute()
        {
            Message = ValidationMessages.IsDate;
        }

        #region Overrides of ValidationAttribute

        public override bool IsValid(object item)
        {

            if (!String.IsNullOrEmpty(item.ToString().Trim()))
            {
                DateTime chkDate;

                if (!DateTime.TryParse(item.ToString(), out chkDate))
                    return false;
            }
            else
                return false;

            return true;
        }

        #endregion
    }
}